<template>
  <el-row class="container">
    <el-col :span="24" class="header">
      <el-col :span="10" class="logo logo-width">
        <a href="/eminer/"><img src="../assets/logo2.png"/></a>
      </el-col>
      <el-col :span="10">
      </el-col>
      <el-col :span="4" class="userinfo">
        <el-dropdown trigger="hover">
          <span class="el-dropdown-link userinfo-inner"> <img src="../assets/user.png"/>{{sysUserName}}</span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="addTabs('3-1', '用户管理')">用户管理</el-dropdown-item>
            <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-col>
    </el-col>

    <el-col :span="24" class="main">
      <aside>
        <leftNav></leftNav>
      </aside>
<section class="content-container">
  <div style="display: block; width: auto; float: right; margin-right: 0; z-index: 3 ">
    <el-button v-if="this.state.tabsList.length > 3" @click="clearTabs">关闭所有标签</el-button>
  </div>
  <div class="grid-content bg-purple-light">
    <el-col :span="24" class="breadcrumb-container" style="float: left">
      <tabs></tabs>
    </el-col>
    <el-col :span="24" class="content-wrapper">
      <transition name="fade" mode="out-in">
        <router-view></router-view>
      </transition>
    </el-col>
  </div>
</section>
</el-col>
</el-row>
</template>

<script>
  import leftNav from './Leftnav.vue'
  import tabs from './tabs.vue'
  export default {
    components: {
      'leftNav': leftNav,
      'tabs': tabs
    },
    data () {
      return {
        sysName: 'EMiner数据挖掘平台',
        collapsed: false,
        sysUserName: '',
        sysUserAvatar: '',
        state: this.$store.state,  // XXX: 直接获取string，修改string不会刷新绑定的值
        form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        }
      }
    },
    methods: {
      onSubmit () {
        console.log('submit!')
      },
      // 退出登录
      logout: function () {  // TODO: 清空状态
        const _this = this
        _this.$confirm('确认退出吗?', '提示', {
          // type: 'warning'
        }).then(() => {
          sessionStorage.clear()
          _this.$router.push('/login')
        }).catch(() => {

        })
      },
      // 折叠导航栏
      collapse: function () {
        this.collapsed = !this.collapsed
      },
      addTabs (key, title) {
        this.$store.dispatch('addTab', {'tab': {
          title: title,
          name: key,
//          content: '<proxy></proxy>',
//          proxy: true,
          components: key,
          closed: true
        },
          'activeName': key})
      },
      clearTabs () {
        this.$store.dispatch('clearTab')
        this.$store.dispatch('addTab', {'tab': {
          title: '首页',
          name: 'main',
          components: '0-0',
          closed: false
        },
          activeName: 'main',
          activeList: ['main']})
      }
    },
    mounted () {
      let user = sessionStorage.getItem('user')
      if (user) {
//        user = JSON.parse(user)
        this.sysUserName = user || ''
//        this.sysUserAvatar = user.avatar || ''
      }
    }
  }

</script>

<style scoped lang="less">
  /*@import '~scss_vars';*/
  .el-dropdown {
    font-size: 18px;
  }
  .container {
    position: absolute;
    top: 0px;
    bottom: 0px;
    width: 100%;
    .header {
      height: 60px;
      line-height: 60px;
      background: #5472d4;
      color:#fff;
      .userinfo {
        text-align: right;
        padding-right: 35px;
        float: right;
        .userinfo-inner {
          cursor: pointer;
          color:#fff;
          img {
            height: auto;
            max-width: 100%;
            vertical-align: middle;
            border: 0;
            margin-right: 5px;
          }
        }
      }
      .logo {
        //width:230px;
        height:60px;
        font-size: 22px;
        padding-left:20px;
        padding-right:20px;
        img {
          width: 420px;
          height: 60px;
          float: left;
          /*margin: 10px 10px 10px 18px;*/
        }
        .txt {
          color:#fff;
        }
      }
      .logo-width{
        width:330px;
      }
      .logo-collapse-width{
        width:60px
      }
      .tools{
        padding: 0px 23px;
        width:14px;
        height: 60px;
        line-height: 60px;
        cursor: pointer;
      }
    }
    .main {
      display: flex;
      // background: #324057;
      position: absolute;
      top: 60px;
      bottom: 0px;
      overflow: hidden;
      aside {
        flex:0 0 230px;
        width: 230px;
        background-color: #1b2737;
        // position: absolute;
        // top: 0px;
        // bottom: 0px;
        .el-menu{
          height: 100%;
        }
        .collapsed{
          width:60px;
          .item{
            position: relative;
          }
          .submenu{
            position:absolute;
            top:0px;
            left:60px;
            z-index:99999;
            height:auto;
            display:none;
          }

        }
      }
      .menu-collapsed{
        flex:0 0 60px;
        width: 60px;
      }
      .menu-expanded{
        flex:0 0 230px;
        width: 230px;
      }
      .content-container {
        // background: #f1f2f7;
        flex:1;
        // position: absolute;
        // right: 0px;
        // top: 0px;
        // bottom: 0px;
        // left: 230px;
        overflow-y: scroll;
        padding: 20px;
        .breadcrumb-container {
          //margin-bottom: 15px;
          .title {
            width: 200px;
            float: left;
            color: #475669;
          }
          .breadcrumb-inner {
            float: right;
          }
        }
        .content-wrapper {
          background-color: #fff;
          box-sizing: border-box;
        }
      }
    }
  }
  .el-table__header .el-table__body {
    width: auto;
    height: auto;
  }
</style>
